cmake_minimum_required(VERSION 3.22)
project(function_test)

set(VAR1_IN_PARENT_SCOPE "parent var1")

# 定义一个函数，接受2个入参，并将入参打印出来
function(print var1 var2)
    message("-- Hello: [${var1}] and [${var2}]")
    message("-- show parent var: ${VAR2_IN_PARENT_SCOPE}")
    set(VAR_DEFINED_IN_FUNCTION "function var" PARENT_SCOPE)
endfunction()

message("before invoke, show var from function: [${VAR_DEFINED_IN_FUNCTION}]")
print("function test" "first time")
message("first invoke, show var from function: [${VAR_DEFINED_IN_FUNCTION}]")

set(VAR_DEFINED_IN_FUNCTION "modify function var")

set(VAR2_IN_PARENT_SCOPE "parent var2")
print("function test" "sencond time")
message("second invoke, show var from function: [${VAR_DEFINED_IN_FUNCTION}]")

function(printex var1 var2 var3)
    message("parameters number: ${ARGC}")
    foreach(var in ${ARGV})
        message("parameter: ${var}")
    endforeach()
endfunction(printex)

printex("a" "b" "c")
